package com.web.music.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class Person implements PersistentEntity,SecuredEntity {
	
	@Id @GeneratedValue
	@Column(name = "PERSON_ID", nullable = false)
	private Long id;

	@Transient
	// this field represents full ID value from XML file, is used in DigesterXmlParser only
	private String idString;
	
	private String name;
	
	private String surname;

	@OneToOne(mappedBy="person")
	@LazyCollection(LazyCollectionOption.FALSE) 
	private Singer singerInfo;

	@ManyToMany(mappedBy="members", cascade={CascadeType.PERSIST, CascadeType.MERGE})
	@LazyCollection(LazyCollectionOption.FALSE) 
	private List<MusicBand> musicBands = new ArrayList<MusicBand>();

	@ManyToOne
	private User createdBy;

	@Transient
	private boolean updateGranted = false;

	public String getName(){
		return name;
	}

	public void setName(String name ){
		this.name = name;
	}

	public String getSurname(){
		return surname;
	}

	public void setSurname(String surname ){
		this.surname = surname;
	}

	public Singer getSingerInfo() {
		return singerInfo;
	}

	public void setSingerInfo(Singer singerInfo) {
		this.singerInfo = singerInfo;
	}

	public List<MusicBand> getMusicBands() {
		return musicBands;
	}

	public void setMusicBands(List<MusicBand> musicBands) {
		this.musicBands = musicBands;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getIdString() {
		return idString;
	}

	public void setIdString(String idString) {
		this.idString = idString;
	}
	public void addMusicBand(MusicBand band){
		this.musicBands.add(band);
	}
	public void setCreatedBy(User createdBy){
		this.createdBy = createdBy;
	}
	public User getCreatedBy(){
		return this.createdBy;
	}

	public boolean getUpdateGranted() {
		return updateGranted;
	}

	public void setUpdateGranted(boolean updateGranted) {
		this.updateGranted = updateGranted;
	}	

}
